import 'package:bruno/bruno.dart';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_widgets_pc/config/kq_global.dart';
import 'package:flutter_widgets_pc/resources/kq_theme_colors.dart';
import 'package:flutter_widgets_pc/utils/event_bus_utils.dart';
import 'package:flutter_widgets_pc/widgets/bottomSheet/kq_botton_sheet_manger.dart';
import 'package:flutter_widgets_pc/widgets/button/kq_head_button.dart';
import 'package:flutter_widgets_pc/widgets/button/kq_ink_well.dart';
import 'package:flutter_widgets_pc/widgets/titleBar/kq_title_bar.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../../config/global.dart';
import '../../../event/theme_change_event.dart';
import '../../../router/route_map.dart';
import 'controller.dart';

/// 首页
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  /// 菜单布局
  Widget gridMenuItem(String menuName, GestureTapCallback? onTap) {
    return BrnShadowCard(
      circular: 20,
      child: InkWell(
        onTap: onTap,
        child: Container(
          color: KqThemeColors.bgWhite,
          padding: EdgeInsets.all(10),
          child: Text(
            menuName,
            style: TextStyle(
              fontWeight: FontWeight.bold,
              color: Colors.black,
              fontSize: 20,
            ),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(HomeController());
    final state = Get.find<HomeController>().state;

    return GetBuilder<HomeController>(
        init: controller,
        builder: (controller) {
          return Scaffold(
            key: state.scaffoldKey,
            appBar: KqHeadBar(
              headTitle: '组件库演示',
              showBack: false,
              actions: KqHeadButton(
                widget: Icon(Icons.color_lens),
                menuData: [
                  KqPopMenuItemData(title: '黄色主题', hasPermission: true),
                  KqPopMenuItemData(title: '红色主题', hasPermission: true),
                  KqPopMenuItemData(title: '蓝色主题', hasPermission: true),
                  KqPopMenuItemData(title: '黑色主题', hasPermission: true),
                ],
                onSelected: (position, entity) {
                  controller.changeTheme(position);
                },
              ),
            ),
            body: GetBuilder<HomeController>(
              builder: (controller) => SmartRefresher(
                enablePullDown: true,
                enablePullUp: false,
                controller: controller.refreshController,
                onRefresh: controller.onRefresh,
                child: GridView.count(
                  crossAxisCount: 2,
                  scrollDirection: Axis.vertical,
                  //宽高比
                  childAspectRatio: 3 / 1.2,
                  padding: EdgeInsets.all(12),
                  mainAxisSpacing: 12,
                  crossAxisSpacing: 12,
                  children: [
                    gridMenuItem('输入框组件', () {
                      RouteMap().goEditorDemo();
                    }),
                    gridMenuItem('按钮组件', () {
                      RouteMap.pushButtonDemo();
                    }),
                    gridMenuItem('表单组件', () {
                      RouteMap.pushFormDemo();
                    }),
                    gridMenuItem('对话框组件', () {
                      RouteMap.pushDialogDemo();
                    }),
                    gridMenuItem('折叠组件', () {
                      RouteMap.pushExpandListDemo();
                    }),
                    gridMenuItem('网格列表组件', () {
                      RouteMap.pushWrapFlowDemo();
                    }),
                    gridMenuItem('下拉菜单', () {
                      RouteMap.pushPullDownDemo();
                    }),
                    gridMenuItem('下拉菜单2', () {
                      RouteMap.pushPullDownSimpleDemo();
                    }),
                    gridMenuItem('表格', () {
                      RouteMap.pushTableDemo();
                    }),
                    gridMenuItem("表格2", () {
                      Get.toNamed("/KqTable2");
                    }),
                    gridMenuItem('手写签名', () {
                      RouteMap.pushSignaturePadDemo();
                    }),
                    gridMenuItem('图表', () {
                      RouteMap.pushChartPage();
                    }),
                    gridMenuItem('面包屑', () {
                      RouteMap.pushBreadCrumbsDemo();
                    }),
                    gridMenuItem('轮播图', () {
                      RouteMap.pushSwiperDemo();
                    }),
                    gridMenuItem('文件选择与文件预览', () {
                      RouteMap.goFilePickerPage();
                    }),
                    gridMenuItem('更多自定义控件演示', () {
                      RouteMap.pushCustomViewsPage();
                    }),
                    gridMenuItem('更多自定义控件演示2', () {
                      RouteMap.pushCustomExpandPage();
                    }),
                    gridMenuItem('底部弹窗', () {
                      KqBottomSheetManager.showBottomSheet(
                        '底部弹窗',
                        child: Container(
                          height: 700,
                        ),
                      );
                    }),
                    gridMenuItem('可选择的gridview', () {
                      RouteMap.pushKqSelectableGridView();
                    }),
                    gridMenuItem('抽屉', () {
                      RouteMap.pushKqDrawer();
                    }),
                    gridMenuItem('溢出组件', () {
                      RouteMap.pushKqOverFlowBox();
                    }),
                    gridMenuItem('时间轴', () {
                      RouteMap.pushKqStepLineDemo();
                    })
                  ],
                ),
              ),
            ),
          );
        });
  }
}
